<template>
  <div class="home-icons">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page,index) of pages" :key="index">
        <div class="icon" v-for="item in page" :key="item.id">
          <div class="icon-img">
            <img class="icon-img-content" :src="item.imgUrl" alt="">
          </div>
          <p class="icon-desc">{{item.desc}}</p>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>
<script>
export default {
  name: "homeIcon",
  props: {
    iconList: Array
  },
  data() {
    return {
      // iconList: [
      //   {
      //     id: 1,
      //     iconImg:
      //       "http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png",
      //     iconDesc: "热门景点"
      //   },
      //   {
      //     id: 2,
      //     iconImg:
      //       "http://img1.qunarzz.com/piao/fusion/1804/ed/cf572be30fc32f02.png",
      //     iconDesc: "Q+精选"
      //   },
      //   {
      //     id: 3,
      //     iconImg:
      //       "http://img1.qunarzz.com/piao/fusion/1803/b1/528a9e80403b8c02.png",
      //     iconDesc: "热门景点"
      //   },
      //   {
      //     id: 4,
      //     iconImg:
      //       "http://img1.qunarzz.com/piao/fusion/1803/75/eca3ce656c886502.png",
      //     iconDesc: "热门景点"
      //   },
      //   {
      //     id: 5,
      //     iconImg:
      //       "http://img1.qunarzz.com/piao/fusion/1803/b8/c5dcdb58deec2402.png",
      //     iconDesc: "热门景点"
      //   },
      //   {
      //     id: 6,
      //     iconImg:
      //       "http://img1.qunarzz.com/piao/fusion/1803/17/99402a22ce4af302.png",
      //     iconDesc: "热门景点"
      //   },
      //   {
      //     id: 7,
      //     iconImg:
      //       "http://img1.qunarzz.com/piao/fusion/1803/e3/67df61427c8e1302.png",
      //     iconDesc: "热门景点"
      //   },
      //   {
      //     id: 8,
      //     iconImg:
      //       "http://img1.qunarzz.com/piao/fusion/1803/8c/47630407f70e8302.png",
      //     iconDesc: "热门景点"
      //   },
      //   {
      //     id: 9,
      //     iconImg:
      //       "http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png",
      //     iconDesc: "热门景点"
      //   }
      // ],
      swiperOption: {
        autoPaly: false
      }
    };
  },
  computed: {
    pages() {
      let pages = [];
      this.iconList.forEach((item, index) => {
        const page = Math.floor(index / 8);
        if (!pages[page]) {
          pages[page] = [];
        }
        pages[page].push(item);
      });
      return pages;
    }
  }
};
</script>
<style lang="stylus" scoped>
@import '~styles/varibles.styl';
@import '~styles/mixins.styl';

.home-icons {
  width: 100%;
  height: 0;
  overflow: hidden;
  padding-bottom: 50%;
  margin-top: 0.1rem;

  .icon {
    position: relative;
    width: 25%;
    height: 0;
    padding-bottom: 25%;
    float: left;
    overflow: hidden;

    .icon-img {
      position: absolute;
      top: 0px;
      left: 0;
      right: 0;
      bottom: 0.44rem;
      box-sizing: border-box;
      padding: 0.1rem;

      .icon-img-content {
        height: 100%;
        display: block;
        margin: 0 auto;
      }
    }

    .icon-desc {
      position: absolute;
      left: 0;
      right: 0;
      bottom: 0;
      height: 0.44rem;
      line-height: 0.44rem;
      color: $darkTextColor;
      text-align: center;
      ellipsis();
    }
  }
}
</style>
